<template>
    <div>
  <h1>新增康复理疗信息页面</h1>
    </div>
    <table class="table">
          <thead>
            <tr>
                <td>项目名称</td>
                <td>
                    <input type="text" v-model="data.rehabilitationName">
                </td>
            </tr>

             <tr>
                <td>时长</td>
                <td>
                       <input type="text" v-model="data.duration">
                </td>
            </tr>

             <tr>
                <td>服务数量</td>
                <td>
                    <input type="text" v-model="data.num">
                </td>
            </tr>

             <tr>
                <td>康复类型</td>
                <td>
                    <select v-model="data.roteId">
                        <option value="0">==请选择康复类型</option>
                        <option v-for="a in op" :value="a.roteId">{{a.roteName}}</option>
                    </select>
                </td>
            </tr>

             <tr>
                <td>佣金</td>
                <td>
                    <input type="text" v-model="data.price">
                </td>
            </tr>

             <tr>
                <td>项目说明</td>
                <td>
                    <textarea v-model="data.rehabiType"></textarea>
                </td>
            </tr>

          <tr>
                <td>状态</td>
                <td>
                  <input type="radio" value="true" name="" v-model="data.iState">启用
                   <input type="radio" value="false" name="" v-model="data.iState">禁用
                </td>
            </tr>
  
             <tr>
                <td></td>
                <td>
                    <input type="button" value="新增" @click="adds">
                </td>
            </tr>

          </thead>
    </table>
</template>


<script setup lang="ts">
 import axios from 'axios';
  import{ref,onMounted} from 'vue';
 import {useRouter} from 'vue-router';
   const router=useRouter();
    onMounted(()=>{
        rotes()
    })
    
  const op=ref([{
    "roteId": 0,
    "roteName": ""
  }])
     const rotes=()=>{
         axios.get("https://localhost:7235/api/Rote/rotes").then(res=>{
              op.value=res.data;

         })
     }

 
  const data=ref({
  "rehabilitationId": 0,
  "code": "string",
  "rehabilitationName": "",
  "duration": 0,
  "num": 0,
  "roteId": 0,
  "price": 0,
  "rehabiType": "",
  "iState": true
    
  })

 const adds=()=>{

     if(data.value.rehabilitationName==""){
         alert("项目名称不能为空")
         return;
     }


   
      if(data.value.duration==0){
       alert("时长不能为空")
       return
       
       }


        let h=/^\d+$/;
          if(h.test(data.value.duration)==false){
 alert("时长只能是整数")
       return
          }




       if(data.value.num==0){
        
          alert("服务数量不能为空")
            return
       }

        let y=/^\d+$/;
          if(y.test(data.value.num)==false){
      alert("时长只能是整数")
       return
          }


        if(data.value.price==0){

       alert("佣金不能为空")
            return
        }

       if(data.value.rehabiType==""){

     alert("项目说明不能为空")
            return
        }

        
 axios.post("https://localhost:7235/api/Rehabilitation/AddAnync",data.value).then(res=>{
      if(res.data>0){
         alert("新增成功")
         router.push("/show")

      }else{
        alert("新增失败")
      }
 })
 }
</script>

<style scoped>

</style>
